/**
* \brief Implementation of 'Visitor' design pattern.
*	 Source file.
* \author Bartosz Kedra (bartosz.kedra@gmail.com)
*/

#include "Visitor.hpp"
#include <boost/shared_ptr.hpp>
#include <vector>
#include <iostream>

typedef boost::shared_ptr<Element> Eptr;

class ElementBCounter : public Visitor
{
public:
	virtual void visit(ElementA& a)
	{
		/* do nothing */
	}
	virtual void visit(ElementB& b)
	{
		elementBCnt++;
	}
	virtual void visit(ElementC& c)
	{
		/* do nothing */
	}
	int countB(std::vector<Eptr>& vec)
	{
		elementBCnt = 0;
		for (std::vector<Eptr>::iterator it = vec.begin(); it != vec.end(); it++)
		{
			(*it)->accept(*this);
		}
		return elementBCnt;
	}
private:
	unsigned elementBCnt;
};

int main()
{
	std::vector<Eptr> vec;
	ElementBCounter visitor;

	vec.push_back(Eptr(new ElementC));
	vec.push_back(Eptr(new ElementB));
	vec.push_back(Eptr(new ElementA));
	vec.push_back(Eptr(new ElementB));
	vec.push_back(Eptr(new ElementB));
	vec.push_back(Eptr(new ElementC));
	vec.push_back(Eptr(new ElementB));
	vec.push_back(Eptr(new ElementC));

	std::cout << "Nr of elements of B type: " << visitor.countB(vec) << std::endl;	
	return 0;
}


